#include ("/_includes/_layout.html")
#define css()
<link href="#(webctx)/resources/css/delivery.css" rel="stylesheet"/>
<style type="text/css">.nav-tabs li{width:100px;}.nav-tabs li a{text-align: center;}</style>
#end	
#@layout("运费模板", "wxmall,点步科技", "Wxmall社区","wxmall") 
#define content()
<div class="wrapper wrapper-content">
		 <div id="page-trade-delivery" class="ibox-content app__content page-trade-delivery">
			<div id="deliveryToolsbar" class="panel-body">
				<select id="del_status_sel" class="control-inline">
				    <option value="">全部</option>
					<option value="1" selected="selected">使用中</option>
					<option value="0">停用</option>
				</select>
				
				<div style="float: left; margin-right: 20px;"><a href="javascript:void(0)" onclick="addMemo();" class="btn btn-success">新建运费模版</a></div>
				<div id="pager" class="jqpager" style="margin-bottom: 1px;float: right;"></div>
			</div>
			
			 <div class="freight-list">
				<div class="freight-content" style="display: block;">
			    <div class="freight-template-list-wrap js-freight-template-list-wrap">
			    	<ul class="deliveryLotGrid"></ul>
			    </div>
			</div>
		 </div>
		 <!-- <div id="deliveryToolsbar" class="panel-body"><div id="pager" class="jqpager" style="margin-bottom: 1px;float: right;"></div> -->
		 </div>
	</div>
</div>
#end
<script type="text/javascript">
function addMemo(){
	location.href=obz.ctx + "/delivery/add";
}
$(function (){
	var s=$("#page-trade-delivery"),i=s.find(".deliveryLotGrid");
	 i.on("click",".js-freight-extend-toggle",function(s){
		 var i=$(this);
		e(i);
	});
});
function e(t){
	"1"==t.data("expend")?(t.find(".freight-extend-toggle").addClass("freight-extend-toggle-extend"),t.data("expend","0"),
	t.siblings().hide()):(t.find(".freight-extend-toggle").removeClass("freight-extend-toggle-extend"),t.data("expend","1"),
	t.siblings().show());
}

var ActivityTableOpt = {
	edit : function(param){
		var id = param[1];
		location.href = obz.ctx + "/delivery/edit/"+id;
	}, 
	
	init : function(){
		var optArray = new Array();
		optArray.push(this.edit);
		return optArray;
	}
}

var params = {};
params.active = $("#del_status_sel").val();
var table = new obz.TableView("pager", obz.ctx + "/delivery/list", params, function(resp){
	$(".deliveryLotGrid").empty();
	var dataList = resp.list;
	if(dataList.length>0){
		for(var i=0;i<dataList.length;i++){
			var _row = dataList[i];
			if(_row.valuationType=="2"){
				var liHtml = obz.dataTemplate4obj($("#freight-template-weight").html(), _row);	
			}else{
				var liHtml = obz.dataTemplate4obj($("#freight-template").html(), _row);
			}
			$(".deliveryLotGrid").append(liHtml);
			for(var j=0;j<_row.deliverySetList.length;j++){
				var s_row=_row.deliverySetList[j];	 
				var trHtml = obz.dataTemplate4obj($("#freight-template_table").html(),s_row);	
				$("#js-freight-cost_"+_row.id).append(trHtml);
			}
		}
		TBatch.initOptEvent(ActivityTableOpt.init());
		
		$(".js-freight-delete").click(function(){
			ids = $(this).attr("data-id");
			obz.showMessage("确定要停用吗？请谨慎操作！", function(){
				 obz.ajaxJson(obz.ctx + "/delivery/del", {ids: ids}, function(resp){
					if(resp.code==200){
						obz.msg('停用成功', function(){
							location.reload();
						});	
					}
				});
			});
		});
	}else{
		$(".deliveryLotGrid").append($("#table_noresult_tr_tpl").html());
	}
});
table.init();
$(document).ready(function() {
	$("#del_status_sel").change(function(){
		params.active = $("#del_status_sel").val();
		table.init();
	});
});
</script>
<script type="text/template" id="freight-template">
 <li class="freight-template-item">
     <h4 class="freight-template-title js-freight-extend-toggle">
    <b>{name}</b> 
    <div class="pull-right">
    <span class="c-gray">最后编辑时间  {startTime}  </span>--
        <a id="edit_{id}" href="#(webctx)/delivery/edit?id={id}" class="js-freight-edit">修改</a>-
        <a href="javascript:void(0);" class="freight-extend-toggle freight-extend-toggle-extend"></a>
    </div>    
    </h4>
		<table class="freight-template-table" style="font-size:12px;">
		    <thead class="js-freight-cost-list-header">
		            <tr>
		                <td>可配送区域</td>
		                <td>首件（个）</td>
		                <td>运费（元）</td>
		                <td>续件（个）</td>
		                <td>续费（元）</td>
		            </tr>
		    </thead>
		    <tbody id="js-freight-cost_{id}"></tbody>
		</table>
        </li>
</script>
<script type="text/template" id="freight-template-weight">
 <li class="freight-template-item">
     <h4 class="freight-template-title js-freight-extend-toggle">
    <b>{name}</b> 
    <div class="pull-right">
    <span class="c-gray">最后编辑时间  {startTime}  </span>--
        <a id="edit_{id}" href="#(webctx)/delivery/edit?id={id}" class="js-freight-edit">修改</a>-
        <a href="javascript:void(0);" class="freight-extend-toggle freight-extend-toggle-extend"></a>
    </div>    
    </h4>
		<table class="freight-template-table" style="font-size:12px;">
		    <thead class="js-freight-cost-list-header">
		            <tr>
		                <td>可配送区域</td>
		                <td>首重（Kg）</td>
		                <td>运费（元）</td>
		                <td>续重（Kg）</td>
		                <td>续费（元）</td>
		            </tr>
		    </thead>
		    <tbody id="js-freight-cost_{id}"></tbody>
		</table>
        </li>
</script>
<script type="text/template" id="freight-template_table">
<tr>
<td><span class="text-depth1">{areaId}</span></td>
<td>{startStandards}</td>
<td>{startFees}</td>
<td>{addStandards}</td>
<td>{addFees}</td>
</tr>
</script>

<script type="text/template" id="table_noresult_tr_tpl">
<p class="c-gray" style="margin: 10px 0 20px 12px">还没有运费模版</p>
</script>